const app = getApp();

Component({
  data: {
    selected: 0,
    color: "#bfbfbf",
    selectedColor: "#fff",
    list: app.globalData.tabbars
  },
  
  lifetimes: {
    attached() {
      app.globalData.tabbarListeners.push(list => this.onTabbarsChange(list));
      this.setData({ list: app.globalData.tabbars });
    },
  },

  methods: {
    onTabbarsChange(list) {
      this.setData({ list });
      // wx.switchTab({
      //   url: '/pages/index/index',
      // });
    },

    switchTab(e) {
      const data = e.currentTarget.dataset;
      const url = data.path;
      wx.switchTab({
        url,
        success: (res) => {
          let page = getCurrentPages().pop();
          if (page == undefined || page == null) return;
        }, fail: err => {
          console.log(err);
        }
      });
    }
  }
})